<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>011-HTML5-Canvas-渐变-圆渐变</title>
</head>

<body>
    <canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
        您的浏览器不支持 HTML5 canvas 标签。</canvas>

    <script>

        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");

        // 创建渐变
        var grd = ctx.createRadialGradient(75, 50, 5, 90, 60, 100); // createRadialGradient(x,y,r,x1,y1,r1) - 创建一个径向/圆渐变
        grd.addColorStop(0, "red");
        grd.addColorStop(1, "white");

        // 创建渐变
        ctx.fillStyle = grd;
        ctx.fillRect(10, 10, 150, 80);

    </script>
</body>

</html>